<%@page import="drukarnia.model.PriceForMaterials"%>
<%@page import="java.util.List"%>
<%@page import="drukarnia.controller.PriceForMaterialsManager"%>
<%@ page import="drukarnia.model.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page errorPage="WEB-INF/bledy.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Drukarnia</title>
</head>
<body>
<h1>Dodaj nowy materiał:</h1>

<%
User user = (User)session.getAttribute("user");
if(user != null && user.getAuthorization() == 'a'){
	String id = request.getParameter("id");
	String empty = "";
	if(id == null){
		
%>
		<form action="PriceForMaterialsAction" method="post">
			<input type="hidden" name="empty" value="true" />
			<center><table>
				<tr> <td> Nazwa materiału: </td> <td> <input type="text" name="typeOfMaterial" /></td></tr>
				<tr> <td>Cena za m2 </td> <td><input type="text" name="price" />zł</td></tr>
				<tr> <td colspan="2">&nbsp</td></tr>
				<tr> <td colspan="1"><input type="submit"  value="Dodaj" /></td>
					<td colspan="1"><button><a href="setPriceForMaterials.jsp">Anuluj</a></button></td>
				</tr>
			</table>
		</center>
	</form>
	
	
	 <% }else{ 
		 
	 	PriceForMaterialsManager man = new PriceForMaterialsManager();
	 	int id_price = Integer.parseInt(id);
	 	List<PriceForMaterials> list = man.fetchPriceAtIdFromDB(id_price);
	 %>
	 	
	 	<form action="PriceForMaterialsAction" method="post">
	 		<input type="hidden" name="empty" value="false" />
	 		<input type="hidden" name="id_price" value="<%= list.iterator().next().getId_price() %>" />
			<center><table>
				<tr> <td> Nazwa materiału: </td> <td> <input type="text" name="typeOfMaterial"  value="<%= list.iterator().next().getTypeOfMaterial() %>"/></td></tr>
				<tr> <td>Cena za m2 </td> <td><input type="text" name="price" value="<%= list.iterator().next().getPrice() %>" />zł</td></tr>
				<tr> <td colspan="2">&nbsp</td></tr>
				<tr> <td colspan="1"><input type="submit"  value="Dodaj" /></td>
					<td colspan="1"><button><a href="setPriceForMaterials.jsp">Anuluj</a></button></td>
				</tr>
			</table>
		</center>
	</form>
		 
	<% }
	

		}else{
		 response.sendError(404,"Drukarnia: brak uprawnien");
	 	}
		 %>

</body>
</html>